/**	 
 * @Description 
 * @Path		com.bbx.taxi.client.Activity.Base.BaseMapBBXActivity.java 
 * @Author		年向   
 * @Date		2015年7月16日 下午5:55:58 
 * @Company	 	蓝海（福建）信息技术有限公司	 
 */
package com.bbx.taxi.client.Activity.Base;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ZoomControls;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.MyLocationConfiguration.LocationMode;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.model.LatLng;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.official.R;

/**
 * @Description
 * @Path com.bbx.taxi.client.Activity.Base.BaseMapBBXActivity.java
 * @Author 年向
 * @Date 2015年7月16日 下午5:55:58
 * @Company 蓝海（福建）信息技术有限公司
 */
public abstract class BaseMapBBXActivity extends BaseBBXActivity {

	private MapView mMapView;
	private BaiduMap mBaiduMap;
	boolean isFirstLoc = true;// 是否首次定位

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		IsSwipeBack = false;
		super.onCreate(savedInstanceState);
		initDefaultLocation();
	}

	public void initDefaultLocation() {
		try{
		// 地图初始化
		mMapView = (MapView) findViewById(R.id.bmapView);
		mMapView.showZoomControls(false);
		mMapView.showScaleControl(false);
		if (mMapView != null&& mMapView.getMap()!=null) {
			mBaiduMap = mMapView.getMap();

			mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(
					LocationMode.NORMAL, true, null));
			if (MyApplication.getInstance().mLocation != null) {// 先默认定位
				MyLocationData locData = new MyLocationData.Builder()
						.accuracy(
								MyApplication.getInstance().mLocation
										.getRadius())
						// 此处设置开发者获取到的方向信息，顺时针0-360
						.direction(100)
						.latitude(
								MyApplication.getInstance().mLocation
										.getLatitude())
						.longitude(
								MyApplication.getInstance().mLocation
										.getLongitude()).build();
				mBaiduMap.setMyLocationData(locData);
				if (isFirstLoc) {
					isFirstLoc = false;
					LatLng ll = new LatLng(
							MyApplication.getInstance().mLocation.getLatitude(),
							MyApplication.getInstance().mLocation
									.getLongitude());
					MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
					mBaiduMap.animateMapStatus(u);
				}
			}else{
				new Handler().postDelayed(new Runnable() {
					
					@Override
					public void run() {
						initDefaultLocation();
					}
				}, 2000);
				
			}
			new Handler().postDelayed(new Runnable() {
				@Override
				public void run() {
					if(mBaiduMap!=null)
					mBaiduMap
							.setMyLocationConfigeration(new MyLocationConfiguration(
									LocationMode.NORMAL, true,
									BitmapDescriptorFactory
											.fromResource(R.drawable.icon_mapid2)));
				}
			}, 100);
			// 开启定位图层
			mBaiduMap.setMyLocationEnabled(true);
		}else{
			new Handler().postDelayed(new Runnable() {
				
				@Override
				public void run() {
					initDefaultLocation();
				}
			}, 2000);
		}
		// 隐藏logo
		View child = mMapView.getChildAt(1);
		if (child != null && (child instanceof ImageView || child instanceof ZoomControls)){            
		     child.setVisibility(View.INVISIBLE);           
		}
		}
		catch(Exception e){}
	}

	@Override
	protected void onPause() {
		super.onPause();
		if (mMapView != null)
			mMapView.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
		if (mMapView != null)
			mMapView.onResume();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (mMapView != null)
			mMapView.onDestroy();
	}
	public void setVisibility(final View v,int Visibility){
		if(Visibility==View.VISIBLE){ 
			v.setVisibility(View.VISIBLE);
			
		}
		else if(Visibility==View.GONE){   
			v.setVisibility(View.GONE);
		    
		}
	}
}
